package com.qckj.amz.controller;

import com.qckj.amz.domain.OrderItem;
import com.qckj.amz.service.IOrderItemService;
import com.qckj.common.annotation.Log;
import com.qckj.common.core.controller.BaseController;
import com.qckj.common.core.domain.AjaxResult;
import com.qckj.common.core.page.TableDataInfo;
import com.qckj.common.enums.BusinessType;
import com.qckj.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;

/**
 * 订单项信息Controller
 *
 * @author luchuan
 * @since 1.0 2021-11-27
 */
@RestController
@RequestMapping("/amz/orderItem")
public class OrderItemController extends BaseController {
    @Autowired
    private IOrderItemService orderItemService;

    /**
     * 查询订单项信息列表
     */
    @PreAuthorize("@ss.hasPermi('amz:orderItem:list')")
    @GetMapping("/list")
    public TableDataInfo list(OrderItem orderItem) {
        Page<OrderItem> page = orderItemService.findOrderItemPage(orderItem);
        return getDataTable(page);
    }

    /**
     * 导出订单项信息列表
     */
    @PreAuthorize("@ss.hasPermi('amz:orderItem:export')")
    @Log(title = "订单项信息", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(OrderItem orderItem) {
        List<OrderItem> list = orderItemService.findOrderItemList(orderItem);
        ExcelUtil<OrderItem> util = new ExcelUtil<>(OrderItem.class);
        return util.exportExcel(list, "orderItem");
    }

    /**
     * 获取订单项信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('amz:orderItem:query')")
    @GetMapping(value = "/{orderItemId}")
    public AjaxResult getInfo(@PathVariable("orderItemId") Long orderItemId) {
        return AjaxResult.success(orderItemService.findById(orderItemId));
    }

    /**
     * 新增订单项信息
     */
    @PreAuthorize("@ss.hasPermi('amz:orderItem:add')")
    @Log(title = "订单项信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody OrderItem orderItem) {
        orderItemService.save(orderItem);
        return AjaxResult.success();
    }

    /**
     * 修改订单项信息
     */
    @PreAuthorize("@ss.hasPermi('amz:orderItem:edit')")
    @Log(title = "订单项信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody OrderItem orderItem) {
        orderItemService.save(orderItem);
        return AjaxResult.success();
    }

    /**
     * 删除订单项信息
     */
    @PreAuthorize("@ss.hasPermi('amz:orderItem:remove')")
    @Log(title = "订单项信息", businessType = BusinessType.DELETE)
	@DeleteMapping("/{orderItemIds}")
    public AjaxResult remove(@PathVariable Long[] orderItemIds) {
        orderItemService.deleteByIds(Arrays.asList(orderItemIds));
        return AjaxResult.success();
    }
}
